# 使用 NVIDIA 提供的官方 CUDA 镜像作为基础镜像，需要使用 nvidia-smi 查看宿主机支持的最大cuda版本，保证容器cuda小于等于宿主机版本
# FROM nvidia/cuda:12.4.1-cudnn-runtime-ubuntu20.04
# FROM nvidia/cuda:12.4.1-cudnn-devel-ubuntu22.04
FROM nvidia/cuda:12.2.2-runtime-ubuntu22.04

LABEL auth="zhough<zhough@zetyun.com>" 

# 设置环境变量
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

# ENV http_proxy=http://172.20.3.88:1088
# ENV https_proxy=http://172.20.3.88:1088

# 安装基础软件包和 Python 3.10
RUN apt-get update && \
    apt install  -y software-properties-common && add-apt-repository ppa:deadsnakes/ppa && apt update && \
    apt install -y --no-install-recommends \
    python3.10 \
    python3.10-dev \
    python3.10-distutils \
    git \
    curl \
    openssh-server && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    python3.10 --version

# 安装对应版本的 pip
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10


# 安装 PyTorch 2.0 及相关库
# RUN pip3 install torch==2.0.0+cu124 torchvision==0.15.0+cu124 torchaudio==2.0.0+cu124 -f https://download.pytorch.org/whl/torch_stable.html
# RUN pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu124
# RUN pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu122
RUN pip3 install torch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 --index-url https://download.pytorch.org/whl/cu121


# 设置 SSH 服务
RUN mkdir /var/run/sshd && unset http_proxy https_proxy
RUN echo 'root:password' | chpasswd

# 允许 root 用户通过 SSH 登录
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# 开放 SSH 端口
EXPOSE 22

# 启动 SSH 服务
CMD ["/usr/sbin/sshd", "-D"]

# 构建镜像的命令
# docker build -t pytorch-cuda:2.0 .
# 

# 一、保存镜像 手动加载
# Step 1: Save the Docker image
# docker save -o pytorch-cuda.tar pytorch-cuda:2.0
# Step 2: Load the image with ctr
# ctr image import pytorch-cuda.tar
# Step 3: Log in to your repository (Docker Hub example)
# ctr --namespace moby images auth login docker.io
# Step 4: Tag the image for your repository
# ctr images tag pytorch-cuda:2.0 docker.io/your-username/pytorch-cuda:2.0
# Step 5: Push the image to the repository
# ctr images push docker.io/your-username/pytorch-cuda:2.0

# 
# docker run -d -p 2222:22 --gpus all --name pytorch_container pytorch-cuda:2.0
# 连接
# ssh root@your_alibaba_cloud_ip -p 2222

# 二、上传到 docker hub
# docker login tableagent-registry.cn-beijing.cr.aliyuncs.com
# docker tag postgres:latest tableagent-registry.cn-beijing.cr.aliyuncs.com/wedding/postgres:latest
# docker push tableagent-registry.cn-beijing.cr.aliyuncs.com/wedding/postgres:latest